import {generate_contract,userExtSign} from '@/request/api'
import {cert_list, com_typeList, ind_typeList} from "@/assets/staticList";
import {return_url} from "@/assets/return_url";
//合同签署
let userExtSignFun = (params) => {
    userExtSign(params).then(res => {
        console.log('params',params)
        console.log('res.sign_url',res.sign_url)
        window.location.href = res.sign_url
    })
}
//合同填充
let generate_contract_func = async (params) => {
    let province = params.province == null ? "" : params.province;
    let city = params.city == null ? "" : params.city;
    let region = params.region = null ? "" : params.region;
    console.log(params)
    let profile = {
        pid: params.id,
        parameter_map: {
            major: params.major,
            org: params.org.org_name,
            exam_org: params.exam_org.org_name,
            course: params.course.name,
            ispass: params.exam_count > 0 ? '是' : '否',
            time_detail: params.exam_date.time_detail,
            exam_city: params.exam_date.exam_city,
            user_name: params.name,
            name_en: params.first_py + ' / ' + params.last_py,
            card_type: params.card_type_display,
            card_id: params.card_id,
            gender: params.gender_display,
            birthday: params.birthday,
            hig_edu: params.hig_edu,
            grad_time: params.grad_time ? params.grad_time.split('-')[0] + '年' + params.grad_time.split('-')[1] + '月' : '',
            cert: params.cert,
            region: province + " " + city + " " + region,
            work_age: params.work_age + "年",
            com_name: params.com_name,
            email: params.email,
            work_duty_cn: params.work_duty.split('#')[0],
            work_duty_en: params.work_duty.split('#')[1],
            sign: "",
            current_date:
                new Date().getFullYear() +
                "年" +
                (new Date().getMonth() + 1) +
                "月" +
                new Date().getDate() +
                "日",
            ind_type: ind_typeList[params.ind_type-1].name,
            com_type: com_typeList[params.com_type-1].name,
            phone: params.phone
        },
    }
    try {
        const res = await generate_contract(profile)
        console.log('合同签署', res);
    } catch (e) {
        //e提示给用户
        alert(e)
        throw e
    }
};
//手动签署
let userExtSign_func = (profile) => {
    userExtSignFun({pid: profile.id, return_url: return_url});
};
export {generate_contract_func,userExtSign_func,userExtSignFun}
